//
//  YDVerticalDetailTopView.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2018/1/7.
//  Copyright © 2018年 LK-IOS. All rights reserved.
//

#import "YDVerticalDetailTopView.h"
#import "YDVerticalStockDetailView.h"
#import "YDVerticalKTimeLineView.h"


@interface YDVerticalDetailTopView()<SYVerticalStockDetailViewDelegate>


@end

@implementation YDVerticalDetailTopView

-(void)setIsTimerData:(BOOL)isTimerData
{
    _isTimerData = isTimerData;
}
-(void)setStockDict:(NSDictionary *)stockDict
{
    _stockDict = stockDict;
    if (![stockDict count])return;
    self.stockDetailView.stockDict = stockDict;
    if (self.isTimerData)return;
    self.KTimeLineView.stockName = [NSString stringWithFormat:@"%@" , stockDict[@"name"]];
    self.KTimeLineView.stockCode = [NSString stringWithFormat:@"%@" , stockDict[@"instrumentId"]];
}
-(void)setStockName:(NSString *)stockName
{
    _stockName = stockName;
    if (!stockName.length)return;
    self.stockDetailView.stockNameS = stockName;
    self.KTimeLineView.stockName = stockName;
    
}
-(void)setStockCode:(NSString *)stockCode
{
    _stockCode = stockCode;
    if (!stockCode.length)return;
    self.stockDetailView.stockCodeS = stockCode;
    self.KTimeLineView.stockCode = stockCode;
}

-(void)setIsActivity:(BOOL)isActivity
{
    _isActivity = isActivity;
    
    self.stockDetailView.isActivity = isActivity;
}
-(void)setIsNormal:(BOOL)isNormal
{
    _isNormal = isNormal;
    self.stockDetailView.isNormal = isNormal;
}
-(void)setOptionStyle:(SYVerticalStockButtonOptionViewStyle)optionStyle
{
    _optionStyle = optionStyle;
    self.stockDetailView.optionViewStyle = optionStyle;
    
    
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:mainGray];
        [self stockDetailView];
        [self KTimeLineView];
    }
    return self;
}

#pragma mark - SYVerticalStockDetailViewDelegate
- (void)didSlectedBtn:(NSString *)title
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(didSlectedBtn:)]) {
        [self.delegate didSlectedBtn:title];
    }
}
+(instancetype)verticalDetailTopViewWithStockDict:(NSDictionary *)stockDict StockName:(NSString *)stockName StockCode:(NSString *)stockCode IsActivity:(BOOL)isActivity IsNormal:(BOOL)isNormal OptionViewStyle:(SYVerticalStockButtonOptionViewStyle)optionStyle
{
    YDVerticalDetailTopView *topView = [[YDVerticalDetailTopView alloc] init];
    topView.stockDict = stockDict;
    topView.stockCode = stockCode;
    topView.stockName = stockName;
    topView.isActivity = isActivity;
    topView.isNormal = isNormal;
    topView.optionStyle = optionStyle;
    return topView;
}
/*单支股票详情topview*/
-(YDVerticalStockDetailView *)stockDetailView
{
    if (_stockDetailView == nil) {
        YDVerticalStockDetailView *stockDetailView = [YDVerticalStockDetailView verticalStockDetailViewWithStockDict:self.stockDict StockName:self.stockName StockCode:self.stockCode IsActivity:self.isActivity IsNormal:self.isNormal OptionViewStyle:self.optionStyle];
        stockDetailView.delegate = self;
        stockDetailView.frame = CGRectMake(0, 0, LKScreenW, isPhoneX ? rateX812(115) : rate750(115));
        [self addSubview:stockDetailView];
        _stockDetailView = stockDetailView;
    }
    return _stockDetailView;
}

/*均线 日K*/
-(YDVerticalKTimeLineView *)KTimeLineView
{
    if (_KTimeLineView == nil) {
        CGFloat timelineViewY = isPhoneX ? rateX812(5) : rate750(5);
        CGRect viewFrame = CGRectMake(0, CGRectGetMaxY(self.stockDetailView.frame) + timelineViewY, LKScreenW, isPhoneX ? rateX812(315) : rate750(315));
        YDVerticalKTimeLineView *KTimeLineView = [YDVerticalKTimeLineView verticalKTimeLineViewInitWithFrame:viewFrame WithStockName:self.stockName StockCode:self.stockCode];

        [self addSubview:KTimeLineView];
        _KTimeLineView = KTimeLineView;
    }
    return _KTimeLineView;
}

-(void)dealloc
{
    DDLog(@"dealloc")
}

-(void)loadDataDidChangeStock
{
    [self.KTimeLineView loadDataDidChangeStock];
}

-(void)openTimer
{
    [self.KTimeLineView openTimer];
}
-(void)stopTimer
{
    [self.KTimeLineView stopTimer];
}

@end
